package com.bhkj.pdjhbgnewproject.core.silenceInstall;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.blankj.utilcode.util.AppUtils;

public class SilenceInstallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        if ("android.intent.action.PACKAGE_REPLACED".equals(intent.getAction())) {
            Toast.makeText(context, "升级了一个安装包，重新启动此程序", Toast.LENGTH_SHORT).show();
            AppUtils.launchApp(AppUtils.getAppPackageName());
        }

        // 接收安装广播
        if ("android.intent.action.PACKAGE_ADDED".equals(intent.getAction())) {
            String packageName = intent.getDataString();
            System.out.println("安装了:" + packageName + "包名的程序");
//            startApp(context);
        }

        //接收卸载广播
        if ("android.intent.action.PACKAGE_REMOVED".equals(intent.getAction())) {
            String packageName = intent.getDataString();
            System.out.println("卸载了:" + packageName + "包名的程序");
        }

    }

}
